//
//  ExchangeRateDetailTableViewController.m
//  汇率换算
//
//  Created by king on 15/11/26.
//  Copyright © 2015年 king. All rights reserved.
//

#import "ExchangeRateDetailTableViewController.h"
#import "ExchangeRateConvert.h"
#import "ExchangeRateConvertModel.h"
#import "ExchangeRateTableViewController.h"

@interface ExchangeRateDetailTableViewController ()

@property(nonatomic, strong) NSArray *exchangeRateConvertArray;

@end

@implementation ExchangeRateDetailTableViewController

#pragma mark - Method viewDidLoad
- (void)viewDidLoad {
    [super viewDidLoad];

    // 设置view背景颜色
    self.view.backgroundColor = [UIColor clearColor];
    self.title = @"选择兑换币种";
    // 获取汇率换算代码表
    self.exchangeRateConvertArray = [[ExchangeRateConvert shareExchangeRateConvert] selectDataFromTableExchangeRateConvert];
    // 注册cell
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"exchangeRateDetailResue"];
}
#pragma mark - Method didReceiveMemoryWarning
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
#pragma mark - Method tableView:numberOfRowsInSection:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.exchangeRateConvertArray.count;
}
#pragma mark - Method tableView:cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"exchangeRateDetailResue" forIndexPath:indexPath];
    ExchangeRateConvertModel *temp = self.exchangeRateConvertArray[indexPath.row];
    cell.textLabel.text = temp.currencyValue;
    return cell;
}
#pragma mark - Method tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //此页面已经存在于self.navigationController.viewControllers中,并且是当前页面的前一页面
    ExchangeRateTableViewController *controller = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2];
    if (self.currencyType == 0) {
        // 待转化币种的简称
        controller.temp.fromCurrency = [self.exchangeRateConvertArray[indexPath.row] currencyKey];
    } else {
        // 转化后的币种的简称
        controller.temp.toCurrency = [self.exchangeRateConvertArray[indexPath.row] currencyKey];
    }
    // 跳转回上个页面
    [self.navigationController popToViewController:controller animated:YES];
}

@end
